package lt.inkredibl.iit;

import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;

public class ZoomTransformer
	implements ICoordTransformer
{
	private int _zoom;

	public ZoomTransformer(int zoom)
	{
		_zoom = zoom;
	}
	
	public int getZoom()
	{
		return _zoom;
	}
	
	public void setZoom(int zoom)
	{
		_zoom = zoom;
	}
	
	/* (non-Javadoc)
	 * @see lt.inkredibl.iit.ICoordTransformer#ui2ic(double)
	 */
	public double ui2ic(double d)
	{
		if (_zoom > 1)
		{
			return d / _zoom;
		}
		else if (_zoom < -1)
		{
			return d * (-_zoom);
		}
		else
		{
			return d;
		}
	}
	
	/* (non-Javadoc)
	 * @see lt.inkredibl.iit.ICoordTransformer#ui2ic(java.awt.geom.Point2D)
	 */
	public Point2D ui2ic(Point2D p)
	{
		return new Point2D.Double(ui2ic(p.getX()), ui2ic(p.getY()));
	}

	/* (non-Javadoc)
	 * @see lt.inkredibl.iit.ICoordTransformer#ui2icInPlace(java.awt.geom.Point2D)
	 */
	public void ui2icInPlace(Point2D p)
	{
		p.setLocation(ui2ic(p.getX()), ui2ic(p.getY()));
	}
	
	/* (non-Javadoc)
	 * @see lt.inkredibl.iit.ICoordTransformer#ic2ui(double)
	 */
	public double ic2ui(double d)
	{
		if (_zoom > 1)
		{
			
			return d * _zoom;
		}
		else if (_zoom < -1)
		{
			return d / (-_zoom);
		}
		else
		{
			return d;
		}
	}
	
	/* (non-Javadoc)
	 * @see lt.inkredibl.iit.ICoordTransformer#ic2uiSize(double)
	 */
	public int ic2uiSize(double d)
	{
		return (int)Math.ceil(ic2ui(d));
	}
	
	/* (non-Javadoc)
	 * @see lt.inkredibl.iit.ICoordTransformer#ic2ui(java.awt.geom.Point2D)
	 */
	public Point2D ic2ui(Point2D p)
	{
		return new Point2D.Double(ic2ui(p.getX()), ic2ui(p.getY()));
	}
	
	/* (non-Javadoc)
	 * @see lt.inkredibl.iit.ICoordTransformer#ic2uiInPlace(java.awt.geom.Point2D)
	 */
	public void ic2uiInPlace(Point2D p)
	{
		p.setLocation(ic2ui(p.getX()), ic2ui(p.getY()));
	}
	
	/* (non-Javadoc)
	 * @see lt.inkredibl.iit.ICoordTransformer#extractPoint(java.awt.event.MouseEvent)
	 */
	public Point2D extractPoint(MouseEvent evt)
	{
		return new Point2D.Double(ui2ic(evt.getX()), ui2ic(evt.getY()));
	}
}
